import { AccountProps, ListData } from '@/store'

const account: AccountProps = {
  name: 'TENDOUZHI',
  sex: '男',
  birth: '2002-11-23'
}

// 首先引入Mock
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Mock = require('mockjs')

Mock.mock('http://apis.imooc.com/api/mock/login?icode=35084F3DAB9C223E',
  ({ body }: any) => {
    if (body) {
      return {
        token: 'the token which is belong to TENDOUZHI',
        response: body.email,
        userName: 'TENDOUZHI'
      }
    }
  })

Mock.mock('http://apis.imooc.com/api/mock/columns?icode=35084F3DAB9C223E',
  'get',
  (res: ListData) => {
    const list = [
      {
        author: '5f3e86d62c56ee13bb830961',
        avatar: {
          _id: '5f3e41a8b7d9c60b68cdd1ec',
          url: 'http://vue-maker.oss-cn-hangzhou.aliyuncs.com/vue-marker/5f3e41a8b7d9c60b68cdd1ec.jpg'
        },
        createdAt: '2020-08-20 22:21:10',
        description: '酒店售货机，酒店经营，共享经济，新零售，共享数据线，关注灵趣科技，了解更多',
        featured: true,
        key: 0,
        title: '铺先生',
        __v: 0,
        _id: '5f3e86d62c56ee13bb83096c'
      },
      {
        author: '5f3e86d62c56ee13bb830960',
        avatar: {
          _id: '5f3e3a17c305b1070f455202',
          url: 'http://vue-maker.oss-cn-hangzhou.aliyuncs.com/vue-marker/5f3e3a17c305b1070f455202.jpg'
        },
        createdAt: '2020-08-20 22:21:10',
        description: '半吊子系统和程序狗，沉迷高端理论，日渐消瘦。',
        featured: true,
        key: 1,
        title: 'Vehicle攻城狮',
        __v: 0,
        _id: '5f3e86d62c56ee13bb83096b'
      },
      {
        author: '5f2918ed59d0b03366c0f0ad',
        avatar: {
          _id: '618795acb558154f0392e68b',
          url: 'http://typescript-vue.oss-cn-beijing.aliyuncs.com/vue-marker/618795acb558154f0392e68b.png'
        },
        createdAt: '2020-08-20 22:21:10',
        description: '欢迎订阅',
        featured: true,
        key: 2,
        title: '前端专栏31',
        _id: '5f4db92abb821789a5490ed3'
      },
      {
        author: '5f3e86d62c56ee13bb83095f',
        avatar: {
          _id: '5f3e41a8b7d9c60b68cdd1ec',
          url: 'http://vue-maker.oss-cn-hangzhou.aliyuncs.com/vue-marker/5f3e41a8b7d9c60b68cdd1ec.jpg'
        },
        createdAt: '2020-08-20 22:21:10',
        description: '公号：高斋CATTI，细致讲解让翻译学习更轻松！',
        featured: true,
        key: 3,
        title: 'CATTI和MTI考研考试资料与资讯',
        __v: 0,
        _id: '5f3e86d62c56ee13bb83096a'
      },
      {
        author: '5f3e86d62c56ee13bb830962',
        avatar: {
          _id: '5f3e3a17c305b1070f455202',
          url: 'http://vue-maker.oss-cn-hangzhou.aliyuncs.com/vue-marker/5f3e3a17c305b1070f455202.jpg'
        },
        createdAt: '2020-08-20 22:21:10',
        description: '鞋神号：  sunmen123123',
        featured: true,
        key: 4,
        title: '我不是鞋神',
        __v: 0,
        _id: '5f3e86d62c56ee13bb830969'
      }]
    if (res) {
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      list.push(res)
    }
    return {
      data: {
        count: 11,
        currentPage: 1,
        list: list,
        msg: '请求成功'
      }
    }
  })
Mock.mock('http://apis.imooc.com/api/mock/edit?icode=35084F3DAB9C223E',
  'post',
  ({ body }: any) => {
    body = JSON.parse(body)
    account.name = body.name
    account.sex = body.sex
    account.birth = body.birth
    return {
      account
    }
  }
)
